package edu.whut.service.impl;

import edu.whut.dao.CommentDao;
import edu.whut.entity.Comment;
import edu.whut.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    CommentDao commentDao;

    @Override
    public Boolean addComment(Comment comment) {
        return commentDao.insert(comment)>0;
    }

    @Override
    public Boolean deleteComment(Comment comment) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("creationId",comment.getCreationId());
        map.put("content",comment.getContent());
        map.put("username",comment.getUsername());
        return commentDao.deleteByMap(map)>0;
    }

    @Override
    public List<Comment> getCommentById(Long creationId) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("creationId",creationId);
        return commentDao.selectByMap(map);
    }

    @Override
    public Integer getCommentNumber(Long creationId) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("creationId",creationId);
        return commentDao.selectByMap(map).size();
    }
}
